#include "Plane.h"

Plane::Plane()
{

}

Plane::Plane(const Vec3f& V0, const Vec3f& V1, const Vec3f& V2)
{
	Vec3f NewV0(V1 - V0);
	Vec3f NewV1(V2 - V0);

	m_Normal = NewV0.CrossProduct(NewV1);
	m_Normal.Normalise();

	m_Distance = V0.DotProduct(m_Normal);
}

float Plane::ReturnDistance(const Vec3f& q) const
{
	 return q.DotProduct(m_Normal) - m_Distance;
}

Plane::PointType Plane::ClassifyPoint(const Vec3f& q)
{
	float Distance = ReturnDistance(q);

	if(Distance == 0)
	{
		return	PT_ON_THE_PLANE;
	}
	else if(Distance < 0)
	{
		return PT_BEHIND;
	}
	else if(Distance > 0)
	{
		return PT_IN_FRONT;
	}
}

float Plane::LineMinPoint(LineSeg& seg)
{
	float P0Dist = ReturnDistance(seg.GetStart());
	float P1Dist = ReturnDistance(seg.GetEnd());

	if(ClassifyPoint(seg.GetStart()) != ClassifyPoint(seg.GetEnd()))
	{
		return 0;
	}

	//get max if it's behind

	//get min if it's in front

}
